/**
 * Created by Administrator on 2018/7/3, 003.
 */
// 参数管理混入的方法
export const mixinParameterManager = {
  created () {
    this.showTabeData()
  },
  methods: {
    // 显示数据列表
    showTabeData () {
      const SELECTData = {
        pageNo: '1',
        pageSize: '10'
      }
      this.packAjax(SELECTData)
    },
    // 条件查询
    conditionquery () {
      const conditiondata = {
        keyword: this.condition
      }
      this.packAjax(conditiondata)
    },
    // 每页显示条目个数
    handleSizeChange: function (val) {
      this.pagesize = val
      this.handleCurrentChange()
    },
    // 当前页数
    handleCurrentChange (val) {
      this.currentPage = val
      const pagelistdata = {
        pageNo: val,
        pageSize: this.pagesize
      }
      this.packAjax(pagelistdata)
    },
    // 勾选当前行
    checkrow (row) {
      if (row.length > 0) {
        this.dialogForm = row[0]
        this.checkbox = row
      }
    },
    // 编辑
    handleEdit () {
      // 判断是否勾选
      if (this.checkbox.length > 0) {
        if (this.checkbox.length < 2) {
          this.addRoleDialogVisiable = true // 显示弹框
          this.editmetadisa = true // meta_id input框禁止修改
          this.addRoleDialogMode = 'MODIFY' // 新增角色对话框模式 编辑模式
          // 获取时间格式化 再添加到时间选择框里面
            // let data = this.dialogForm
            // this.te_date = data.te_date
            // this.le_date = data.le_date
            // this.dialogForm.date = [this.te_date, this.le_date]
          // 定义变量接收一下当前对象
          this.currentItem = JSON.parse(JSON.stringify(this.dialogForm))
          // 解除双向绑定
          this.dialogForm = JSON.parse(JSON.stringify(this.dialogForm))
        } else {
          this.$message.error('只能选择一条记录进行编辑')
        }
      } else {
        this.$message.error('请选择一条记录进行编辑')
      }
    },
    // 增加按钮
    adddialogForm () {
      this.dialogForm = {}
      this.addRoleDialogVisiable = true
      this.addRoleDialogMode = 'ADD'
      this.editmetadisa = false
    },
    // 关闭
    cancel () {
      this.addRoleDialogVisiable = false
      this.editdialogform = false
      this.dialogForm = {...this.currentItem}
      this.$refs.dialogForm.clearValidate()
    },
    // 重置
    resetForm () {
      // 如果是编辑进第一个判断
      this.$refs.dialogForm.clearValidate()
      if (this.addRoleDialogMode !== 'ADD') {
        this.dialogForm = {...this.currentItem}
      } else {
        this.dialogForm = {}
      }
    },
    // 勾选框事件
    handleSelectionChange (val) {
      let checkedCount = val.length
      // 判断是不是全选
      if (checkedCount === this.tableData.length) {
        this.checkbox.length = checkedCount
      }
      this.list = []
      for (let i = 0; i < val.length; i++) {
        let remdata = {
          meta_id: val[i].meta_id
        }
        this.list.push(remdata)
      }
    }
  }
}
export const codeEscape = {
  methods: {
    escape (data, type, key) {
      if (data === undefined || data.length === 0) {
        return null
      }
      key = String(key)
      let useData = data[type]
      let result
      for (let i = 0; i < useData.length; i++) {
        if (useData[i]['code_value'] === key) {
          result = useData[i]['code_value_nm_cns']
        }
      }
      return result
    }
  }
}
